import { JupiterUser, JupiterUserQuery, JupiterUserRole } from '../types/userTypes';
import request from 'utils/request';

export const fetchUserList = (params: JupiterUserQuery) => {
  return request.post('/users/page', params);
};

export const fetchUserById = (uuid: string) => {
  return request.get(`/users/${uuid}`);
};

export const createUser = (data: Partial<JupiterUser>) => {
  return request.post('/users', data);
};

export const updateUser = (uuid: string, data: Partial<JupiterUser>) => {
  return request.put(`/users/${uuid}`, data);
};

export const deleteUser = (uuid: string) => {
  return request.delete(`/users/${uuid}`);
};

export const updateUserStatus = (uuid: string, status: number) => {
  return request.put(`/users/${uuid}/status`, { status });
};

export const resetUserPassword = (uuid: string) => {
  return request.put(`/users/${uuid}/password/reset`);
};

export const fetchUserRoles = (userId: string) => {
  return request.get(`/user-roles/user/${userId}`);
};

export const assignRolesToUser = (data: Partial<JupiterUserRole>) => {
  return request.post(`/user-roles/assign-roles-to-user`, data);
};

export const fetchUserRoleList = (params: any) => {
  return request.get('/user-roles/page', { params });
};

export const createUserRole = (data: Partial<JupiterUserRole>) => {
  return request.post('/user-roles', data);
};

export const deleteUserRole = (uuid: string) => {
  return request.delete(`/user-roles/${uuid}`);
};

export const restoreUser = (uuid: string) => {
  return request.post(`/users/restoreUser/${uuid}`, {});
};
